import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;


public class Performance {

	public static void main(String[] args) throws Exception {
	
		//loop();
		copyFiles();
	}
	
	private static void loop() {
		
		long start = System.currentTimeMillis();
		
		int size = 6000000;
		String[] arr = new String[size];
		for (int i=0; i < size; i++) {
			arr[i] = "0123456789";
		}
		System.out.println("time assigning " + size + " strings: " + (System.currentTimeMillis() - start) + " millisec.");
		
		start = System.currentTimeMillis();
		for (int i = 0; i < arr.length; i++) {
			if (arr[i].startsWith("some string"))
				System.out.println("found!");
		}
		System.out.println("time checking " + size + " strings: " + (System.currentTimeMillis() - start) + " millisec.");
		
		MemoryTester.getObjectDump(arr, false);
	}
	
	private static void copyFiles() throws IOException {
		File srcFile = new File("C:/_Temp/big_folder/image.tif");
		System.out.println("source file dir: " + srcFile.getParent() + 
				"\nsource file name: " + srcFile.getName() + 
				"\n exists? " + srcFile.exists() + ", size: " + srcFile.length());

		int num = 1000000;
		long start = System.currentTimeMillis();
		
//		for (int i=1; i <= num; i++) {
//			File destFile = new File(srcFile.getParent() + "/" + "image" + i + ".tif");
//			FileUtils.copyFile(srcFile, destFile);
//		}
//		System.out.println("Time copying " + num + " files: " + (System.currentTimeMillis() - start) + " millisec");
		
		
//		start = System.currentTimeMillis();
//		String[] fileNames = srcFile.getParentFile().list();
//		System.out.println("Time listing " + fileNames.length + " files: " + (System.currentTimeMillis() - start) + " millisec");
//		
//		start = System.currentTimeMillis();
//		String testString = "test string";
//		for (int i=0; i < fileNames.length; i++) {
//			if (fileNames[i].startsWith(testString)) {
//				System.out.println("found " + testString);
//			}
//		}
//		System.out.println("Time iterating " + fileNames.length + " files: " + (System.currentTimeMillis() - start) + " millisec");
//		
//		MemoryTester.getObjectDump(fileNames, false);
//		MemoryTester.getObjectDump(fileNames[0], false);
		
		File f = new File(srcFile.getParent() + "/" + "some file.ext");
		System.out.println(f.getAbsolutePath() + " exists? " + f.exists());
		
		System.out.println("getAbstractPath: " + srcFile.getAbsolutePath());
		System.out.println("getPath: " + srcFile.getPath());
		System.out.println("getParent: " + srcFile.getParent());
		System.out.println("path separator: " + File.pathSeparator);
		System.out.println("separator: " + File.separator);
		
	}
}
